package com.sqy.read;

import com.sqy.common.Num;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;

public class ReadPdf {
    public static void read(String path,String encoding) throws Exception {
        File file=new File(path);
        FileInputStream inputStream = new FileInputStream(file);
        PDDocument document = PDDocument.load(inputStream);
        PDFTextStripper stripper = new PDFTextStripper();
        stripper.setSortByPosition(true);
        String result = stripper.getText(document);
        document.close();

        FileWriter writer;
        try {
            
            writer = new FileWriter(Num.PATH);
            writer.write(result);
            writer.flush();
            ReadTxt.read(Num.PATH,encoding);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        
        
    }
}
